﻿using Kinlo.Model.Enum;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace KINLO.UI.Main.Converter
{
    public class State_CodeTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null&& !string.IsNullOrWhiteSpace(value.ToString()))
            {
                State_CodeType enumKey = (State_CodeType)Enum.ToObject(typeof(State_CodeType), int.Parse(value.ToString()));
                return enumKey;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
            {
                State_CodeType enumValue = (State_CodeType)Enum.Parse(typeof(State_CodeType), value.ToString());
                return (int)enumValue;
            }
            return null;
        }
    }
}
